package com.xiyu.service.repository.bed.bed;

import com.xiyu.service.model.bed.bed.BedType;
import com.xiyu.service.model.bed.bed.BedTypeTable;
import com.xiyu.service.vo.bed.bedInfo.BedInfoBedTypeQueryInput;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;
import org.springframework.util.StringUtils;

import java.util.Optional;

public interface BedTypeRepository extends JRepository<BedType, Long> {
    BedTypeTable bedTypeTable = BedTypeTable.$;

    default Page<BedType> pageQuery(BedInfoBedTypeQueryInput inputVO){
        return sql().createQuery(bedTypeTable)
                .whereIf(StringUtils.hasText(inputVO.getTypeName()), () ->  bedTypeTable.typeName().like(inputVO.getTypeName()))
                .orderBy(bedTypeTable.id().desc())
                .select(bedTypeTable)
                .fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());
    }

    Optional<BedType> findFirstByTypeName(String typeName);

    Optional<BedType> findFirstByTypeNameAndIdNot(String typeName,Long id);


}